<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>promise的链式调用</title>
</head>

<body>
    <script>
        function runAsync1() {
            let p = new Promise(function (resolve, reject) {
                //做一些异步操作
                setTimeout(function () {
                    console.log("异步任务执行完毕!");
                    resolve("数据1");
                }, 2000);
            });
            return p;
        }

        function runAsync2() {
            let p = new Promise(function (resolve, reject) {
                //做一些异步操作
                setTimeout(function () {
                    console.log("异步任务执行完毕!");
                    resolve("数据2");
                }, 2000);
            });
            return p;
        }

        function runAsync3() {
            let p = new Promise(function (resolve, reject) {
                //做一些异步操作
                setTimeout(function () {
                    console.log("异步任务执行完毕!");
                    resolve("数据3");
                }, 2000);
            });
            return p;
        }
        runAsync1().then(function (data) {
            console.log(data)
            return runAsync2()
        }).then(function (data) {
            console.log(data)
            return runAsync3()
        }).then(function (data) {
            console.log(data)
        })
    </script>

    <!-- 
 Promise的状态:
   resolve: 成功
   reject: 失败
   then(resolve,reject)

   promise常用方法: then() catch() all()

     -->
</body>

</html>